home *** CD-ROM | disk | FTP | other *** search
/ Total Network Tools 2002 / NextStepPublishing-TotalNetworkTools2002-Win95.iso / Archive / Web Server / PHP.EXE / pear / PHPDoc / accessor / PhpdocIndexAccessor.php < prev    next >
Encoding:
PHP Script  |  2001-02-18  |  9.2 KB  |  360 lines

  1. <?php
  2. /**
  3. * Provides a API to access Index xml documents.
  4. */
  5. class PhpdocIndexAccessor extends PhpdocAccessor {
  6.  
  7.     /**
  8.     * Ordered list of all chapternames.
  9.     *
  10.     * @var  array
  11.     */
  12.     var $chapternames = array();
  13.     
  14.     /**
  15.     * Ordered list of all chapters.
  16.     *
  17.     * @var  array
  18.     */
  19.     var $chapters = array();
  20.     
  21.     /**
  22.     * List of all packages.
  23.     *
  24.     * @var  array
  25.     */
  26.     var $packages = array();
  27.     
  28.     /**
  29.     * Data of a classtree
  30.     *
  31.     * @var    array
  32.     */
  33.     var $classtree = array();
  34.     
  35.     /**
  36.     * Data of a modulegroup
  37.     *
  38.     * @var  array
  39.     */
  40.     var $modulegroup = array();
  41.     
  42.     /**
  43.     * Some container withing the packagelist.
  44.     *
  45.     * @var  array
  46.     * @see  buildPackagelist()
  47.     */
  48.     var $packageFields = array("class", "module");
  49.     
  50.     /**
  51.     * Flag indicating that certain internal datafield have been filled.
  52.     *
  53.     * @var  array
  54.     */
  55.     var $flagBuild = array(
  56.                             "chapter"        => false,
  57.                             "package"        => false
  58.                         );
  59.  
  60.  
  61.     /**
  62.     * Returns a modulegroup
  63.     * 
  64.     * @access   public
  65.     */
  66.     function getModulegroup() {
  67.         
  68.         $this->buildModulegroup();
  69.         
  70.         if ($this->freeOnGet) {
  71.             
  72.             $data = $this->modulegroup;
  73.             $this->modulegroup = array();
  74.             return $data;
  75.             
  76.         } else {
  77.         
  78.             return $this->modulegroup;
  79.         }
  80.         
  81.     } // end func getModulegroup
  82.                                                 
  83.     /**
  84.     * Returns a classtree.
  85.     *
  86.     * @return   array
  87.     * @access   public
  88.     */        
  89.     function getClasstree() {
  90.  
  91.         $this->buildClasstree();
  92.         
  93.         if ($this->freeOnGet) {
  94.         
  95.             $data = $this->classtree;
  96.             $this->classtree = array();
  97.             return $data;
  98.             
  99.         } else {
  100.             
  101.             return $this->classtree;
  102.             
  103.         }
  104.         
  105.     } // end func getClasstree
  106.     
  107.     /**
  108.     * Returns an ordered list of all chapternames.
  109.     * 
  110.     * @return   array
  111.     * @access   public
  112.     * @see      getChapters()
  113.     */
  114.     function getChapternames() {
  115.     
  116.         $this->buildChapterlist();
  117.         
  118.         if ($this->freeOnGet) {
  119.         
  120.             $data = $this->chapternames;
  121.             $this->chapternames = array();
  122.             return $data;
  123.             
  124.         } else {
  125.         
  126.             return $this->chapternames;
  127.             
  128.         }
  129.         
  130.     } // end func getChapternames
  131.     
  132.     /**
  133.     * Returns an ordered list of all chapters.
  134.     * 
  135.     * @return   array
  136.     * @access   public
  137.     * @see      getChapternames()
  138.     */
  139.     function getChapters() {
  140.     
  141.         $this->buildChapterlist();
  142.         
  143.         if ($this->freeOnGet) {
  144.             
  145.             $data = $this->chapters;
  146.             $this->chapters = array();
  147.             return $data;
  148.                 
  149.         } else {
  150.         
  151.             return $this->chapters;
  152.             
  153.         }
  154.         
  155.     } // end func getChapters
  156.     
  157.     /**
  158.     * Returns a list of all packages
  159.     *
  160.     * @return   array
  161.     * @access   public
  162.     */
  163.     function getPackagelist() {
  164.     
  165.         $this->buildPackagelist();
  166.  
  167.         if ($this->freeOnGet) {
  168.             
  169.             $data = $this->packages;
  170.             $this->packages = array();
  171.             return $data;
  172.             
  173.         } else {
  174.             
  175.             return $this->packages;
  176.             
  177.         }
  178.         
  179.     } // end func getPackagelist
  180.     
  181.     
  182.     /**
  183.     * Builds the internal packagelist.
  184.     */
  185.     function buildPackagelist() {
  186.     
  187.         if ($this->flagBuild["package"])
  188.             return;
  189.         
  190.         $data = $this->xml["packagelist"];
  191.         $this->xml = array();
  192.         $this->flagBuild["package"] = true;
  193.         
  194.         $this->packages = array();
  195.         
  196.         if (!isset($data["package"][0]))
  197.             $data["package"] = array($data["package"]);
  198.             
  199.         reset($data["package"]);
  200.         while (list($k, $package) = each($data["package"])) {
  201.             
  202.             $packagename = $package["name"];
  203.             
  204.             reset($this->packageFields);
  205.             while (list($k, $field) = each($this->packageFields)) {
  206.                 
  207.                 if (isset($package[$field][0])) {
  208.                     
  209.                     reset($package[$field]);
  210.                     while (list($k, $element)=each($package[$field]))
  211.                         $this->packages[$packagename][$field][] = $element["name"];
  212.                      
  213.                 } else if (isset($package[$field])) {
  214.                     
  215.                     $this->packages[$packagename][$field][] = $package[$field]["name"];
  216.                     
  217.                 }
  218.             }
  219.             
  220.         }
  221.         
  222.     } // end func buildPackagelist
  223.     
  224.     /**
  225.     * Builds the internal chapterlists. 
  226.     */
  227.     function buildChapterlist() {
  228.     
  229.         if ($this->flagBuild["chapter"])
  230.             return;
  231.             
  232.         $data = $this->xml["index"];
  233.         $this->xml = array();
  234.         $this->flagBuild["chapter"] = true;
  235.  
  236.         $this->chapternames = array();
  237.         $this->chapters = array();
  238.         
  239.         if (isset($data["chapter"][0])) {
  240.             
  241.             $chapterlist = array();
  242.             reset($data["chapter"]);
  243.             while (list($k, $chapter) = each($data["chapter"])) 
  244.                 $chapterlist[strtoupper($chapter["char"])][$chapter["char"]] = $k;
  245.                 
  246.             ksort($chapterlist, SORT_STRING);
  247.             
  248.             reset($chapterlist);
  249.             while (list($k, $chapters) = each($chapterlist)) {
  250.             
  251.                 reset($chapters);
  252.                 while (list($chapter, $index)=each($chapters)) {
  253.                     $this->chapternames[] = $chapter;
  254.                     $this->chapters[$chapter] = $data["chapter"][$index];
  255.                 }
  256.                                     
  257.             }
  258.             
  259.         } else {
  260.             
  261.             $this->chapternames[] = $data["chapter"]["char"];
  262.             $this->chapters[$data["chapter"]["char"]] = $data["chapter"]["char"];
  263.             
  264.         }
  265.         
  266.     } // end func buildChapterlist
  267.  
  268.     /**
  269.     * Extracts the modulegroup data of the xml file.
  270.     * 
  271.     * @see  getModulegroup()
  272.     */
  273.     function buildModulegroup() {
  274.         
  275.         if ($this->flagBuild["modulegroup"])
  276.             return;
  277.             
  278.         $this->flagBuild["modulegroup"] = true;
  279.         $data = $this->xml["modulegroup"];
  280.         
  281.         $this->xml = "";
  282.         $this->modulegroup = array(
  283.                                     "group"        => $data["name"],
  284.                                     "modules"    => array()
  285.                                 );
  286.         
  287.         if (!isset($data["module"][0]))
  288.             $data["module"] = array( $data["module"] );
  289.         
  290.         reset($data["module"]);
  291.         while (list($k, $module) = each($data["module"]))
  292.             $this->modulegroup["modules"][] = $module["name"];
  293.             
  294.     } // end func buildModulegroup
  295.     
  296.     /**
  297.     * Extracts the classtree data of the xml file. 
  298.     *
  299.     * @see  getClasstree()
  300.     */    
  301.     function buildClasstree() {
  302.     
  303.         if ($this->flagBuild["classtree"])
  304.             return;
  305.             
  306.         $this->flagBuild["classtree"] = true;
  307.         $data = $this->xml["classtree"];
  308.         $this->xml = "";
  309.         
  310.         $this->classtree = array( 
  311.                                 "baseclass"    => $data["baseclass"], 
  312.                                 "classes"     => array()
  313.                             );
  314.                                                         
  315.         if (!isset($data["class"][0]))
  316.             $data["class"] = array( $data["class"] );
  317.  
  318.         reset($data["class"]);
  319.         while (list($k, $class)=each($data["class"])) {
  320.             
  321.             if (!isset($class["subclass"])) {
  322.             
  323.                 $this->classtree["classes"][$class["name"]] = array();                
  324.                 
  325.             } else {
  326.                 
  327.                 if (!isset($class["subclass"][0])) {
  328.                 
  329.                     $this->classtree["classes"][$class["name"]][] = $class["subclass"]["value"];
  330.                     
  331.                 } else {
  332.                 
  333.                     reset($class["subclass"]);
  334.                     while (list($k, $subclass)=each($class["subclass"]))
  335.                         $this->classtree["classes"][$class["name"]][] = $subclass["value"];
  336.                         
  337.                 }
  338.                 
  339.             }
  340.             
  341.         }
  342.         
  343.     } // end func buildClasstree
  344.     
  345.     /**
  346.     * Resets the build flags.
  347.     *
  348.     * @see    $flagBuild
  349.     */                                            
  350.     function init() {
  351.         
  352.         reset($this->flagBuild);
  353.         while (list($k, $v) = each($this->flagBuild))
  354.             $this->flagBuild[$k] = false;
  355.             
  356.     } // end func init
  357.  
  358.     
  359. } // end class PhpdocIndexAccessor
  360. ?>